x86: Some cleanups for apic_write, apic_read, apic_wrmsr, apic_rdmsr
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 7 Sep 2009 12:51:37 +0000 (13:51 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 7 Sep 2009 12:51:37 +0000 (13:51 +0100)
Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>
xen/arch/x86/apic.c
xen/include/asm-x86/apic.h

index ba6b0dbb3dfe40dee1eb6fed6d7bd1dbdd007bf6..a590bdfef82bd443567122fa48cf622d60bd6adb 100644 (file)
@@ -627,8 +627,7 @@ int lapic_suspend(void)
     apic_pm_state.apic_id = apic_read(APIC_ID);
     apic_pm_state.apic_taskpri = apic_read(APIC_TASKPRI);
     apic_pm_state.apic_ldr = apic_read(APIC_LDR);
-    if ( !x2apic_enabled )
-        apic_pm_state.apic_dfr = apic_read(APIC_DFR);
+    apic_pm_state.apic_dfr = apic_read(APIC_DFR);
     apic_pm_state.apic_spiv = apic_read(APIC_SPIV);
     apic_pm_state.apic_lvtt = apic_read(APIC_LVTT);
     apic_pm_state.apic_lvtpc = apic_read(APIC_LVTPC);
@@ -654,7 +653,7 @@ int lapic_resume(void)
 {
     unsigned int l, h;
     unsigned long flags;
-    int maxlvt = get_maxlvt();
+    int maxlvt;
 
     if (!apic_pm_state.active)
         return 0;
@@ -679,8 +678,7 @@ int lapic_resume(void)
 
     apic_write(APIC_LVTERR, ERROR_APIC_VECTOR | APIC_LVT_MASKED);
     apic_write(APIC_ID, apic_pm_state.apic_id);
-    if ( !x2apic_enabled )
-        apic_write(APIC_DFR, apic_pm_state.apic_dfr);
+    apic_write(APIC_DFR, apic_pm_state.apic_dfr);
     apic_write(APIC_LDR, apic_pm_state.apic_ldr);
     apic_write(APIC_TASKPRI, apic_pm_state.apic_taskpri);
     apic_write(APIC_SPIV, apic_pm_state.apic_spiv);
@@ -688,6 +686,7 @@ int lapic_resume(void)
     apic_write(APIC_LVT1, apic_pm_state.apic_lvt1);
     apic_write(APIC_LVTTHMR, apic_pm_state.apic_thmr);
 
+    maxlvt = get_maxlvt();
     if (maxlvt >= 6) {
         apic_write(APIC_CMCI, apic_pm_state.apic_lvtcmci);
     }
index 8353c4a21aa04839dc51545cc7ca0dd338df5641..99826c7b27e0697b5afcbfac5f987062210fc19d 100644 (file)
@@ -77,6 +77,10 @@ static __inline u32 apic_mem_read(unsigned long reg)
 
 static __inline void apic_wrmsr(unsigned long reg, u32 low, u32 high)
 {
+    if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
+        reg == APIC_LVR)
+        return;
+
     __asm__ __volatile__("wrmsr"
             : /* no outputs */
             : "c" (APIC_MSR_BASE + (reg >> 4)), "a" (low), "d" (high));
@@ -84,6 +88,11 @@ static __inline void apic_wrmsr(unsigned long reg, u32 low, u32 high)
 
 static __inline void apic_rdmsr(unsigned long reg, u32 *low, u32 *high)
 {
+    if (reg == APIC_DFR)
+    {
+        *low = *high = -1u;
+        return;
+    }
     __asm__ __volatile__("rdmsr"
             : "=a" (*low), "=d" (*high)
             : "c" (APIC_MSR_BASE + (reg >> 4)));